package message.read;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import message.entity.Entity;

/**
 * @ClassName Reader
 * @Description TODO
 * @Author zhangwenkai
 * @Date 2020年6月5日 下午9:10:39
 * @Version 1.0
 */
public class Read {
	

	public Read() {
		
		}
	public List<String> readFile(){
		
		try {
			List<String> list = new ArrayList<String>();
			InputStream input = this.getClass().getResourceAsStream("/EntityInfo.xlsx");
			XSSFWorkbook wb = new XSSFWorkbook(input);
			XSSFSheet sheet = wb.getSheetAt(0);
			DataFormatter dataFormatter = new DataFormatter();
			for (int i = 1; i <= sheet.getLastRowNum(); i++) {
				Row row = sheet.getRow(i);
				Entity e = new Entity();
				for (int j = 0; j < row.getLastCellNum(); j++) {
					Cell cell = row.getCell(j);
					if (cell != null) {
						String value = dataFormatter.formatCellValue(cell);
						if (j == 0) {
							e.setName(value);
						}
						if (j == 1) {
							e.setSex(value);
						}
						if (j == 2) {
							e.setProfession(value);
						}
					}
				}
				System.out.print(e.getName());
				list.add(e.getName() + " " + e.getSex() + " " + e.getProfession());
			}
			wb.close();
			return list;
			
		}catch(FileNotFoundException e) {
			e.printStackTrace();
			
		} catch (IOException e2) {
			
			e2.printStackTrace();
			
		}
		return null;
	}
}
